<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
                    <el-form-item label="房屋ID（对应租金记录）" prop="houseId">
                      <el-input v-model="formData.houseId" placeholder="请输入关联租金表ID（对应租金记录）" />
                    </el-form-item>
                    <!-- <el-form-item label="调整前租金金额（单位：元）" prop="oldRent">
                      <el-input v-model="formData.oldRent" placeholder="请输入调整前租金金额（单位：元）" />
                    </el-form-item> -->
                    <el-form-item label="调整后租金金额（单位：元）" prop="newRent">
                      <el-input v-model="formData.newRent" placeholder="请输入调整后租金金额（单位：元）" />
                    </el-form-item>
                    <!-- <el-form-item label="申请人ID（关联用户表）" prop="applicantId">
                      <el-input v-model="formData.applicantId" placeholder="请输入申请人ID（关联用户表）" />
                    </el-form-item> -->
                    <el-form-item label="审批人ID（关联用户表，审批完成前为空）" prop="approverId">
                      <el-input v-model="formData.approverId" placeholder="请输入审批人ID（关联用户表，审批完成前为空）" />
                    </el-form-item>
                    <el-form-item label="租金调整原因说明（500字以内）" prop="applyReason">
                      <el-input v-model="formData.applyReason" placeholder="请输入租金调整原因说明（500字以内）" />
                    </el-form-item>
                    <!-- <el-form-item label="审批状态（PENDING-待审批/APPROVED-已通过/REJECTED-已拒绝）" prop="auditStatus">
                      <el-radio-group v-model="formData.auditStatus">
                            <el-radio label="1">请选择字典生成</el-radio>
                      </el-radio-group>
                    </el-form-item> -->
                    <!-- <el-form-item label="驳回原因说明（仅驳回时需填写）" prop="rejectReason">
                      <el-input v-model="formData.rejectReason" placeholder="请输入驳回原因说明（仅驳回时需填写）" />
                    </el-form-item> -->
                    <!-- <el-form-item label="申请提交时间" prop="applyTime">
                      <el-date-picker clearable v-model="formData.applyTime" type="date" value-format="timestamp" placeholder="选择申请提交时间" />
                    </el-form-item> -->
                    <!-- <el-form-item label="审批操作时间（通过/驳回时更新）" prop="auditTime">
                      <el-date-picker clearable v-model="formData.auditTime" type="date" value-format="timestamp" placeholder="选择审批操作时间（通过/驳回时更新）" />
                    </el-form-item> -->
      </el-form>
              <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as RentAdjustAuditApi from '@/api/system/rentadjustaudit';
      export default {
    name: "RentAdjustAuditForm",
    components: {
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,
        // 表单参数
        formData: {
                            auditId: undefined,
                            rentId: undefined,
                            oldRent: undefined,
                            newRent: undefined,
                            applicantId: undefined,
                            approverId: undefined,
                            applyReason: undefined,
                            auditStatus: undefined,
                            rejectReason: undefined,
                            applyTime: undefined,
                            auditTime: undefined,
        },
        // 表单校验
        formRules: {
                        rentId: [{ required: true, message: '关联租金表ID（对应租金记录）不能为空', trigger: 'blur' }],
                        oldRent: [{ required: true, message: '调整前租金金额（单位：元）不能为空', trigger: 'blur' }],
                        newRent: [{ required: true, message: '调整后租金金额（单位：元）不能为空', trigger: 'blur' }],
                        applicantId: [{ required: true, message: '申请人ID（关联用户表）不能为空', trigger: 'blur' }],
                        houseId: [{
        required: true,
        message: '房屋ID不能为空',
        trigger: 'blur'
      }],
        },
                        };
    },
    methods: {
      /** 打开弹窗 */
     async open(id) {
        this.dialogVisible = true;
        this.reset();
              },
     /** 提交申请 */
     async submitForm() {
      // 校验表单
      await this.$refs["formRef"].validate();
      this.formLoading = true;
      try {
        const data = this.formData;
        // 调用 submitApply 接口提交申请
        await RentAdjustAuditApi.submitApply(data);
        this.$modal.msgSuccess("申请提交成功");
        this.dialogVisible = false;
        this.$emit('success');
      } catch (error) {
        this.$modal.msgError("申请提交失败：" + error.message);
      } finally {
        this.formLoading = false;
      }
    },
                      /** 表单重置 */
      reset() {
        this.formData = {
                            auditId: undefined,
                            rentId: undefined,
                            oldRent: undefined,
                            newRent: undefined,
                            applicantId: undefined,
                            approverId: undefined,
                            applyReason: undefined,
                            auditStatus: undefined,
                            rejectReason: undefined,
                            applyTime: undefined,
                            auditTime: undefined,
        };
        this.resetForm("formRef");
      },

      
    }
  };
</script>
